﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TMIS.DAL
{
    public class Summary
    {
        private Model.ThesisDB db = new Model.ThesisDB();
        /// <summary>
        /// 根据ID号查找记录
        /// </summary>
        /// <param name="guid">ID号</param>
        /// <returns>如果存在返回true，不存在返回false</returns>
        public bool Search(Guid guid)
        {
            int count = (from s in db.Summary
                         where s.ID == guid
                         select s).Count();
            if (count != 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 根据ID号更新数据库中对应信息
        /// </summary>
        /// <param name="guid"></param>
        /// <param name="summary"></param>
        public void Update(Guid guid, Model.Summary summary)
        {
            Model.Summary sum = db.Summary.Single(e => e.ID == guid);
            sum.Decription = summary.Decription;
            db.SubmitChanges();
        }
        /// <summary>
        /// 将新的工作总结表信息写入到数据库中
        /// </summary>
        /// <param name="summary"></param>
        public void Add(Model.Summary summary)
        {
            db.Summary.InsertOnSubmit(summary);
            db.SubmitChanges();
        }
        /// <summary>
        /// 获取指定ID号的工作总结表
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        public Model.Summary Get(Guid guid)
        {
            Model.Summary sum = (from s in db.Summary
                                 where s.ID == guid
                                 select s).FirstOrDefault();
            return sum;
        }
    }
}
